
import Vue from "vue";
import  { Tooltip } from 'view-design'

//页面状态相关
let status = {
  modalCustomer:{
    isShow : false,
    isLoading : false
  },
  modalCustomerInfo:{
    isShow : false,
    isLoading : false
  }
};

// 和网络交互相关的参数
let params = {
  website : "",
  selectedUsers:[],
  isOnlyInfoed: false,
  selectedUrls:[],
};

// 页面的数据源
let data = {
  websiteList: [],
  customerList: [],
  customerInfo : {}
};

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 60,
  currentPage: 1
};

//个人站列表
let websiteTableTitles=function (self) {
  return [
    {
      type: 'selection',
      width: 60,
      fixed: 'left',
      align: 'center',
    },
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    {
      title: '用户独立站',
      key: 'website',
      align:'center',
      minWidth: 200,
    },
    {
      title: '重复数',
      width: 100,
      key: 'c',
    },
    {
      title: '操作',
      key: 'operation',
      width: 120,
      render: (h, params) => {
        return h('Button', {
          props: {type: 'primary', size: 'small', icon: "md-hand"},
          style: {
            marginRight: '10px', paddingTop: "4px", marginTop: '6px', marginBottom: '6px',
          },
          on: {
            click: () => {
              self.showSameWebsiteCustomers(params.row.website);
            }
          }
        }, '处理')
      }
    }
  ];
};

let customerTableTitles = function (self) {
  return [
    {
      type: 'selection',
      align: 'center',
      fixed: 'left',
      width: 60
    },
    {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    {
      title: '用户名',
      width: 150,
      key: 'name',
      align:'center',
      render: (h, params) => {
        let userName = params.row.name? params.row.name :"";
        let hideName = Vue.prototype.$tiyHideUsername(userName);
        let hasAuth = self.$authority("OPERATIONS-2-201");
        if (!hasAuth){
          return (<div><Tooltip content={userName} placement="top">{hideName}</Tooltip></div>);
        } else{
          return (
            <div>
              <Tooltip content={userName} placement="top">
                <a onClick={()=>{
                  self.getCustomerDetail(params.row.id, params.row.state);
                }}>{hideName}</a>
              </Tooltip>
            </div>
          );
        };
      }
    },
    {
      title: '内部编号',
      width: 180,
      key: 'number',
      render: (h, params) => {
        let hasAuth = self.$authority("OPERATIONS-2-201");
        if (!hasAuth){
          return (<div>{params.row.number}</div>);
        } else{
          return (
            <div>
                <a onClick={()=>{
                  self.getCustomerDetail(params.row.id, params.row.state);
                }}>{params.row.number}</a>
            </div>
          );
        };
      }
    },
    {
      title: '邮箱',
      width: 100,
      key: 'externalEmail',
      render: (h, params) => {
        return params.row.externalEmail?h("div","有"):h("div","");
      }
    },
    {
      title: '负责员工',
      width: 120,
      key: 'employeeName',
    },
    {
      title: '沟通次数',
      width: 90,
      key: 'contactCount'
    },
    {
      title: '站内信地址',
      key: 'contactUrl',
      width: 100,
      render: (h, params) => {
        return params.row.contactUrl ? h("div", [h('a', {
          attrs: {
            target: "_blank", href: params.row.contactUrl
          }
        }, "访问站内信")]) : h("div", "");
      }
    },
    {
      title: '状态',
      width: 110,
      key: 'state',
      render:(h, params) =>{
        return h('div', self.targetCustomerStateDict.filter(item => item.value == params.row.state)[0].name);
      }
    },
    {
      title: '导入时间',
      width: 140,
      key: 'createtime',
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.createtime));
      }
    }
  ];
};

//记录列表
let recordTable=function (self) {
  return [
    {
      type: 'index',
      title: '#',
      width: 70,
      key: 'index',
      fixed: 'left',
      align: 'center',
    },
    {
      title: '员工',
      width: 140,
      key: 'employeeName',
    },
    {
      title: '操作',
      width: 160,
      key: 'operation',
      render: (h, params) => {
        return h('div', self.customerOperationDict.filter(item => item.value == params.row.operation)[0].name);
      }
    },
    {
      title: '备注',
      key: 'notes'
    },
    {
      title: '操作时间',
      width: 140,
      key: 'createtime',
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.createtime));
      }
    },
  ];
};

export  default  {
  tStatus: status,
  tParams: params,
  tData: data,
  tPage: page,
  websiteTableTitles:websiteTableTitles,
  customerTableTitles:customerTableTitles,
  recordTable : recordTable
};
